//
//  ValuationFormulaView.swift
//  AmountBody
//
//  Created by smm on 2018/2/1.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

import UIKit

@objcMembers
class ValuationFormulaView: UIView {
    // MARK:- 懒加载的属性
    /// tableView的属性
    lazy var tableView : UITableView = UITableView()
    lazy var cancelTap = UITapGestureRecognizer.init(target:self, action: #selector(cancelFunc))
    var cellArray: [Data] = []
    let names = ["西服", "西裤", "马甲"]
    let title = ["面料加工费定价规范(300.50)=", "面料加工费定价规范(300.50)=", "面料加工费定价规范(300.50)="]
    let content = ["面料价格(110)*面料折扣(1)*单耗()+CMT价格+(^*%^*())", "面料价格(110)*面料折扣(1)*单耗()+CMT价格+(^*%^*())", "面料价格(110)*面料折扣(1)*单耗()+CMT价格+(^*%^*())"]
    let cg_view = UIView()
    let headerView = HeadlineView()
    private func loadArray() {
        for (index,name) in names.enumerated() {
            let data = Data(title:title[index],name:name,content:content[index])
            cellArray.append(data)
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        loadArray()
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        loadArray()
        setupUI()
        
    }
    
    
    
}
// MARK:- 手势按钮方法
extension ValuationFormulaView {
    func cancelFunc() {
        print("单击")
        self.removeFromSuperview()
    }
}
// MARK:- 设置UI界面相关
extension ValuationFormulaView: UITableViewDelegate,UITableViewDataSource
{
    /// 设置UI界面
    func setupUI() {
        self.addGestureRecognizer(cancelTap);
        self.addSubview(cg_view)
        cg_view.addSubview(headerView)
        headerView.label.text = "计价公式"
        headerView.mas_remakeConstraints{ (make) in
            make?.top.equalTo()(cg_view)?.offset()(10)
            make?.centerX.equalTo()(cg_view)
            make?.height.equalTo()(60)
            make?.width.equalTo()(160)
        }
        cg_view.backgroundColor = UIColor.white
        cg_view.layer.cornerRadius = 8.0
        let ViewW = 600
        let ViewH = 450
        cg_view.mas_remakeConstraints { (make) in
            make?.centerY.centerX().equalTo()(self)
            make?.height.equalTo()(ViewH)
            make?.width.equalTo()(ViewW)
        }
        cg_view.addSubview(tableView)
        tableView.mas_remakeConstraints { (make) in
            make?.edges.equalTo()(cg_view)?.insets()(UIEdgeInsetsMake(80, 20, 20, 20))
        }
        
        // 2.设置数据源
        tableView.dataSource = self
        
        // 3.设置代理
        tableView.delegate = self
        
        tableView.separatorStyle = .none
        tableView.registerCellClass(with: ValuationFormulaViewCell.self)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cellArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let data = cellArray[indexPath.row]
        let cell: ValuationFormulaViewCell = tableView.dequeueReusableCell(for: indexPath)
        cell.data = data as? Data
        return cell
    }
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return 180
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    
}


struct Data {
    let title: String
    let name: String
    let content: String
}
